package cn.geminis.crypto.cert.service.service;

import cn.geminis.crypto.cert.service.model.*;

import java.util.Objects;

/**
 * @author puddi
 */
public interface CertService {

    CertSignResponse sign(CertSignRequest request);

    CertRevokeResponse revoke(CertRevokeRequest request);

    CertDelayResponse delay(CertDelayRequest request);

    default CertSignResponse update(CertUpdateRequest request) {
        if (Objects.isNull(request.getPublicKey())) {
            //加密证书，撤销原有证书
            var revokeRequest = new CertRevokeRequest();
            revokeRequest.setSerialNumber(request.getOldSerialNumber());
            revokeRequest.setReason(request.getReason());
            revoke(revokeRequest);
        }
        return sign(request);
    }

    default CertRevokeResponse freeze(CertRevokeRequest request) {
        request.setReason(3);
        return revoke(request);
    }

    CertResumeResponse resume(CertResumeRequest request);

}
